<!--
 * @Author: your name
 * @Date: 2021-01-05 09:47:34
 * @LastEditTime: 2021-01-12 08:59:05
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /vue-admin-boot/src/pages/home/index.vue
-->
<template>
  <div>
    <el-row>
      <el-button type="primary" @click="goLogin">登录界面</el-button>
      <el-button type="success" @click="goHome">管理页面</el-button>
      <el-button type="primary" @click="httpGet">HTTP-GET</el-button>
      <el-button type="primary" @click="ping">ws心跳</el-button>
      <el-button type="primary" @click="closeWs">ws关闭</el-button>
      <el-button type="primary" @click="goPlayer">视频播放</el-button>
      <el-button type="primary" @click="goFlvPlayer">Flv视频Demo</el-button>
      <el-button type="primary" @click="goNewWindow">测试跳转新页面</el-button>
    </el-row>
  </div>
</template>

<script>
import PreventBack from "@/utils/PreventBackUtil";
export default {
  data() {
    return {
      h: "hello",
    };
  },
  mixins: [PreventBack],
  mounted() {
    this.$root.$on("ws-onMessage", (data) => {
      console.log("-------首页----------");
      console.log(data);
    });
  },
  methods: {
    goLogin() {
      this.$router.push("/login");
    },
    goHome() {
      this.$router.push("/demo");
    },
    httpGet() {
      console.log("axios get");
      this.axios
        .get("/app/proxy/socket/regChannel", {
          // headers: { NeedToken: false },
          params: { usercode: "1000000" },
        })
        .then((res) => {
          console.log("----response--");
          console.log(res);
        })
        .catch((e) => {
          console.log("----error--");
          console.log(e);
        });
    },
    ping() {
      this.$root.$wsClient.sendMessage(
        JSON.stringify({
          prt: "20000",
          cmd: "ping",
          dev: "test123456",
        }),
      );
    },
    closeWs() {
      this.$root.$wsClient.close();
    },
    goPlayer() {
      this.$router.push("/video-player");
    },
    goFlvPlayer() {
      this.$router.push("/flv-player-demo");
    },
    goNewWindow() {
      let newpage = this.$router.resolve({
        path: "/demo/dashboard",
        query: {
          objectType: 1,
          infoId: "1234",
        },
      });
      console.log(newpage.href);
      window.open(newpage.href, "_blank");
    },
  },
};
</script>

<style  scoped>
.el-header {
  background-color: #b3c0d1;
  color: #333;
  line-height: 60px;
}

.el-aside {
  color: #333;
}
</style>